package com.rp.android_gateway.controller;


import com.rp.android_gateway.entity.Gateway;
import com.rp.android_gateway.service.GatewayService;
import com.rp.common.result.ResultDTO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 网关 前端控制器
 * </p>
 *
 * @author vicente
 * @since 2021-11-09
 */
@RestController
@RequestMapping("/gateway")
@Api(tags = "网关管理模块")
public class GatewayController {
    @Autowired
    GatewayService gatewayService;

    @PostMapping("/")
    public ResultDTO add(@RequestBody Gateway gateway){
        boolean save = gatewayService.save(gateway);
        return ResultDTO.tf(save);
    }
    @DeleteMapping("/{id}")
    public ResultDTO del(@PathVariable String id){
        boolean b = gatewayService.removeById(id);
        return ResultDTO.tf(b);
    }
    @GetMapping("/all")
    public ResultDTO<List<Gateway>> getAll(){
        List<Gateway> list = gatewayService.list();
        return ResultDTO.success().data(list);
    }
    @GetMapping("/{id}")
    public ResultDTO<Gateway> get(@PathVariable String id){
        Gateway byId = gatewayService.getById(id);
        return ResultDTO.success().data(byId);
    }

}
